package com.egzosn.entity.pay;


import com.egzosn.pay.ali.api.AliPayConfigStorage;
import com.egzosn.pay.common.api.PayService;
import com.egzosn.pay.common.bean.BasePayType;
import com.egzosn.pay.common.bean.TransactionType;
import com.egzosn.pay.common.http.HttpConfigStorage;
import com.egzosn.pay.wx.api.WxPayConfigStorage;
import com.egzosn.pay.wx.api.WxPayService;
import com.egzosn.pay.wx.bean.WxTransactionType;


/**
 * 支付类型
 *
 * @author egan
 * email egzosn@gmail.com
 * date 2016/11/20 0:30
 */
public enum PayType implements BasePayType {

    aliPay{
        /**
         * @param account
         * @return
         */
        @Override
        public PayService getPayService(PayAccount account) {
            AliPayConfigStorage configStorage = new AliPayConfigStorage();
            configStorage.setAttach(account.getPayId());
            configStorage.setPid(account.getPartner());
            configStorage.setAppId(account.getAppid());
            configStorage.setKeyPublic(account.getPublicKey());
            configStorage.setKeyPrivate(account.getPrivateKey());
            configStorage.setNotifyUrl(account.getNotifyUrl());
            configStorage.setReturnUrl(account.getReturnUrl());
            configStorage.setSignType(account.getSignType());
            configStorage.setSeller(account.getSeller());
            configStorage.setPayType(account.getPayType().toString());
            configStorage.setMsgType(account.getMsgType());
            configStorage.setInputCharset(account.getInputCharset());
            configStorage.setTest(account.isTest());
            return new com.egzosn.pay.ali.api.AliPayService(configStorage);
        }

        @Override
        public TransactionType getTransactionType(String transactionType) {

            // AliTransactionType 17年更新的版本,旧版本请自行切换
            return  com.egzosn.pay.ali.bean.AliTransactionType.valueOf(transactionType);
        }


    },wxPay {
        @Override
        public PayService getPayService(PayAccount account) {
            WxPayConfigStorage configStorage = new WxPayConfigStorage();
            configStorage.setAttach(account.getPayId());
            configStorage.setMchId(account.getPartner());
            configStorage.setSecretKey(account.getPrivateKey());
            configStorage.setAppid(account.getAppid());
            configStorage.setKeyPrivate(account.getPrivateKey());
            configStorage.setNotifyUrl(account.getNotifyUrl());
            configStorage.setSignType(account.getSignType());
            configStorage.setPayType(account.getPayType().toString());
            configStorage.setMsgType(account.getMsgType());
            configStorage.setInputCharset(account.getInputCharset());
            configStorage.setTest(account.isTest());
            //https证书设置 方式一
        /*    HttpConfigStorage httpConfigStorage = new HttpConfigStorage();
            httpConfigStorage.setKeystore("证书信息串");
            httpConfigStorage.setStorePassword("证书密码");
            //是否为证书地址
            httpConfigStorage.setPath(false);
            return  new WxPayService(wxPayConfigStorage, httpConfigStorage);*/
            return  new WxPayService(configStorage);
        }

        /**
         * 根据支付类型获取交易类型
         * @param transactionType 类型值
         * @see WxTransactionType
         * @return
         */
        @Override
        public TransactionType getTransactionType(String transactionType) {

            return WxTransactionType.valueOf(transactionType);
        }
    };

    public abstract PayService getPayService(PayAccount account);


}
